import { wechatInit } from "@/api/user";

export function wxShare(field,store_id,userId,imgUrl){
      wechatInit({url: field}).then(res=>{
            console.log(res)
            if (res.code === 20000) {
                wx.config({
                  debug: false,
                  appId: res.data.appid,
                  timestamp: res.data.timestamp,
                  nonceStr: res.data.noncestr,
                  signature: res.data.signature,
                  jsApiList: ['onMenuShareAppMessage']
                });
                wx.ready(function() {
                    wx.onMenuShareAppMessage({
                      title: '维康宝创富平台', // 分享标题
                      desc: '诚挚邀请您加入，共飨大健康财富盛筵', // 分享描述
                      link: location.protocol+'//'+location.host+"/share?storeId="+store_id+"&pid="+userId, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                      imgUrl: imgUrl, // 分享图标
                      // type: '', // 分享类型,music、video或link，不填默认为link
                      // dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                      success: function (res) {
                          console.log('onMenuShareAppMessage')
                          console.log(res)

                      },
                      fail: function (res) {
                          console.log('fail')
                          console.log(res)
                      }
                    });
                })
            } else {
                console.log('wechatInit失败')
            }
      })
}
